$().ready(function () {
    validateRule();
    
    
    $('#typeNumTable').hide();
    $('input[type=radio][name=calculatetype]').change(function() {
        if (this.value == 0) {
            /**按重量计费**/
            $('#typeWeightTable').show();
            $('#typeNumTable').hide();
        } else if (this.value == 1) {
            /**按件计费**/
            $('#typeWeightTable').hide();
            $('#typeNumTable').show();
        }
    });
});
$.validator.setDefaults({
    submitHandler: function () {
        save();
    }
});

function save() {
    $.ajax({
        cache: true,
        type: "POST",
        url: "/mall/dispatch/save",
        data: $('#signupForm').serialize(),// 你的formid
        async: false,
        error: function (request) {
            parent.layer.alert("Connection error");
        },
        success: function (data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                if (data.msg) {
                    parent.layer.alert(data.msg)
                } else {
                    window.location.href = "/";
                }
            }

        }
    });
}


function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            dispatchname: {
                required: true
            }
        },
        messages: {
            dispatchname: {
                required: icon + "邮费模板不能为空"
            }
        }
    })
}